package net.pm.core.web.addr;

import java.util.Set;

import net.pm.core.cache.CityCache;
import net.pm.core.cache.DistrictCache;
import net.pm.core.cache.ProvinceCache;
import net.pm.core.entities.db.City;
import net.pm.core.entities.db.District;
import net.pm.core.entities.db.Province;
import net.pm.core.web.BaseController;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/addr/")
@Controller
@Scope("request")
public class AddrController extends BaseController {

	@RequestMapping(value = "province",method=RequestMethod.GET)
	public @ResponseBody
	Set<Province> obtainProvinces() {
		Set<Province> provinceSet = ProvinceCache.getProvinceSet();
		return provinceSet;
	}

	@RequestMapping(value = "city",method=RequestMethod.GET)
	public @ResponseBody
	Set<City> obtainCities(@RequestParam("provinceCode") String provinceCode) {
		Set<City> citySet = CityCache.obtainCitiesByProvinceCode(provinceCode);
		return citySet;
	}

	@RequestMapping(value = "district",method=RequestMethod.GET)
	public @ResponseBody
	Set<District> obtainDistricts(@RequestParam("cityCode") String cityCode) {
		Set<District> districtSet = DistrictCache
				.obtainDistrictsByCityCode(cityCode);
		return districtSet;
	}

}
